package SerialCom;

/**
 * Enum description
 *
 */
public class RS485Status {

    private rxState currentState;

    public rxState getCurrentState() {
        return currentState;
    }

    public void setCurrentState(rxState currentState) {
        this.currentState = currentState;
    }
    public RS485Status() {
        this.currentState = rxState.WAIT_START;
    }

    public enum rxState {

        WAIT_START, WAIT_ADDR_HIGH, WAIT_ADDR_LOW, PKT_CMD, WAIT_LEN, WAIT_DATA, WAIT_CRC_HIGH, WAIT_CRC_LOW, COMPLETE, VALID, INVALID
    }

    public enum errState {

        BAD_LENGTH, BAD_CRC, OK_CRC
    }

    /*public rxState nextRxState() {
    //rxState b = this.currentState;
    int i;
    rxState state;

    // stateIterator = rxState.COMPLETE;
    i = this.getCurrentState().ordinal();
    i++;

    if (i < this.getCurrentState().values().length) {
    state.setCurrentState(this.getCurrentState().values()[i]);
    } else {
    i = 0;
    this.setCurrentState(this.getCurrentState().values()[i]);
    }
    return this.getCurrentState();
    }*/

    public void setNextRxState() {
        //rxState b = this.currentState;
        int i;


        // stateIterator = rxState.COMPLETE;
        i = this.getCurrentState().ordinal();
        i++;

        if (i < this.getCurrentState().values().length) {
            this.setCurrentState(this.getCurrentState().values()[i]);
        } else {
            i = 0;
            this.setCurrentState(this.getCurrentState().values()[i]);
        }
        
    }

    public errState okStatus() {

        return errState.OK_CRC;
    }
}